package cn.page;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class OnlineUserNumberListener implements HttpSessionListener {

	private int num;
	public OnlineUserNumberListener() {

	}

	public void sessionCreated(HttpSessionEvent se) {
		num++;
		ServletContext context = se.getSession().getServletContext();
		context.setAttribute("onlineUserNum", num);
	}

	public void sessionDestroyed(HttpSessionEvent se) {
		num--;
		ServletContext context = se.getSession().getServletContext();
		context.setAttribute("onlineUserNum", num);
	}

}
